package com.example.qxfw.yjqx.controller;

import com.example.qxfw.common.SysResult;
import com.example.qxfw.common.entity.yj.Emergency;
import com.example.qxfw.mongodb.hy.entity.HyDocFile;
import com.example.qxfw.mongodb.hy.service.DocFileService;
import com.example.qxfw.ybzz.service.BaseProductService;
import com.example.qxfw.ybzz.service.SysConfigService;
import com.example.qxfw.yjqx.service.EmergencyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.util.List;

@Slf4j
@Api(tags = "应急气象-应急历史")
@RestController
@CrossOrigin
@RequestMapping("/yjls")
public class YjlsController {

    @Autowired
    private SysConfigService sysConfigService;

    @Autowired
    private EmergencyService emergencyService;

    @Autowired
    private BaseProductService baseProductService;

    @ApiOperation("获取配置信息")
    @GetMapping("/getSysConfig")
    public SysResult getSysConfig(String paramName){
        List<String> templates = sysConfigService.getTemplates(paramName);
        return SysResult.success(templates);
    }

    @ApiOperation("查询应急历史")
    @GetMapping("/getEmergency")
    public SysResult getEmergency(String type,String time1,String time2){
        List<Emergency> list = emergencyService.getList(type, time1, time2);
        return SysResult.success(list);
    }

    @ApiOperation("删除应急历史")
    @GetMapping("/deleteEmergency")
    public SysResult deleteEmergency(Integer id){
        Integer rows = emergencyService.delete(id);
        return SysResult.success(rows);
    }

    @ApiOperation("获取Doc路径")
    @GetMapping("/getDocPath")
    public SysResult getDocPath(String id){
        List<String> docPath = emergencyService.getDocPath(id);
        return SysResult.success(docPath);
    }

    @ApiOperation("获取产品id")
    @GetMapping("/getBaseProductId")
    public SysResult getFileName(String productName){
         List<String> id = baseProductService.getId(productName);
         System.out.println("id"+id);

         return SysResult.success(id);


    }

}
